package Creational.Singleton;

import org.testng.annotations.Test;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class EnumDemo {

	@Test
	public void t1() {
		Type instance1 = Type.INSTANCE;
		Type instance2 = Type.INSTANCE;
		System.out.println(instance1 == instance2);
	}

	@Test(description = "序列化测试 这里没生效")
	public void t2() throws Exception {
		Type instance1 = Type.INSTANCE;
		ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream("target/test"));
		outputStream.writeObject(instance1);
		outputStream.close();

		ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream("target/test"));
		Type instance2 = ((Type) inputStream.readObject());
		inputStream.close();
		System.out.println(instance1 == instance2);
	}
}

enum Type {
	INSTANCE;
}
